<template>
  <div>
    <el-row :gutter="10">
      <el-col class="info"
              :xs="7"
              :sm="7"
              :md="7"
              :lg="7">
        <Info :userInfo="userInfo"
              @delTag="delTag"
              @addTag="addTag"
              @submit="submit" />
      </el-col>
      <el-col class="tabs"
              :xs="14"
              :sm="14"
              :md="14"
              :lg="14">
        <Tab />
      </el-col>
    </el-row>
  </div>
</template>
<script>
import Info from "./info";
import Tab from "./tab";
import { userInfo, updateUserInfo } from "@/api/account";
import { addSkill, delSkill } from "@/api/skill";
import { Message } from "element-ui";
export default {
  components: {
    Info,
    Tab
  },
  data() {
    return {
      userInfo: {
        skill: [],
        info: {
          avatar: "",
          nick_name: "",
          remark: "",
          job: "",
          address: ""
        }
      }
    };
  },
  async created() {
    await this.getUserInfo();
  },
  methods: {
    async getUserInfo() {
      this.userInfo = await userInfo();
    },
    async delTag(id) {
      await delSkill(id);
      await this.getUserInfo();
      Message({
        message: "删除成功",
        type: "success",
        center: true,
        duration: 2 * 1000
      });
    },
    async addTag(val) {
      await addSkill(val);
      await this.getUserInfo();
      Message({
        message: "添加成功",
        type: "success",
        center: true,
        duration: 2 * 1000
      });
    },
    async submit(info) {
      await updateUserInfo(info);
      await this.getUserInfo();
      Message({
        message: "编辑成功",
        type: "success",
        center: true,
        duration: 2 * 1000
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.info {
  min-width: 400px;
  margin-bottom: 20px;
}
.tabs {
  min-width: 400px;
}
</style>

